package com.huluobo.a2112mvvmdouyindemo.demoMVP;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.huluobo.a2112mvvmdouyindemo.R;

public class LoginDemoActivity extends AppCompatActivity implements LoginDemoView {

    private LoginDemoPresenter loginPresenter = new LoginDemoPresenter(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_mvp_demo);
        EditText username = findViewById(R.id.login_demo_username);
        EditText password = findViewById(R.id.login_demo_password);
        Button btn = findViewById(R.id.login_demo_btn);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loginPresenter.login(username.getText().toString(), password.getText().toString());
            }
        });

    }

    @Override
    public void onSuccess(UserDemoBean userBean) {
        Toast.makeText(this, "登录成功:" + userBean.getUsername() + "," + userBean.getPassword(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onFailed(String error) {
        Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
    }
}